<?php

use think\migration\Migrator;
use think\migration\db\Column;

class DeliverLine extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $this->table('deliver_line', ['comment' => '路线'])
             ->addColumn('company_id', 'integer', ['limit' => 10, 'after' => 'id', 'default' => 0, 'comment' => '公司ID'])
             ->addColumn('no', 'string', ['limit' => 50, 'after' => 'company_id', 'default' => '', 'comment' => '编号'])
             ->addColumn('name', 'string', ['limit' => 50, 'after' => 'no', 'default' => '', 'comment' => '名称'])
             ->addColumn('deliver_driver_id', 'integer', ['limit' => 10, 'after' => 'name', 'default' => 0, 'comment' => '司机ID'])
             ->addColumn('warehouse_id', 'integer', ['limit' => 10, 'after' => 'deliver_driver_id', 'default' => 0, 'comment' => '起点(仓库ID)'])
             ->addColumn('status', 'integer', ['limit' => 1, 'default' => 1, 'after' => 'warehouse_id', 'comment' => '1:正常,2:禁用'])
             ->addColumn('create_time', 'integer', ['limit' => 10, 'after' => 'status', 'default' => 0, 'comment' => '创建时间'])
             ->addColumn('update_time', 'integer', ['limit' => 10, 'after' => 'create_time', 'default' => 0, 'comment' => '更新时间'])
             ->addColumn('delete_time', 'integer', ['limit' => 10, 'after' => 'update_time', 'default' => 0, 'comment' => '删除时间'])
             ->create();

        $this->table('store')
            ->addColumn('deliver_line_id', 'integer', ['limit' => 10, 'after' => 'salesman_id', 'default' => 0, 'comment' => '路线ID'])
            ->update();
    }
}
